package cn.kgc.itrip.biz.service.impl;

import cn.kgc.itrip.beans.common.ServerResponse;
import cn.kgc.itrip.beans.model.pojo.ItripUser;
import cn.kgc.itrip.biz.service.IlinkUserService;
import cn.kgc.itrip.mapper.itripUserLinkUser.ItripUserLinkUserMapper;
import cn.kgc.itrip.util.RedisApi;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 阿泽
 * @Date 2019/9/26 11:39
 */
@Service("ilinkUserService")
public class linkUserServiceimpl implements IlinkUserService {

    @Resource
    private ItripUserLinkUserMapper itripUserLinkUserMapper;
    @Resource
    private RedisApi redisApi;
    /**
     * 查询常用联系人接口
     *
     * @param linkUserName 如果linkUserName为空就查所有如果有查询单个的
     * @return
     */

    @Override
    public ServerResponse queryLinkUserList(String token,String linkUserName) {
        if (StringUtils.isBlank(token)) {
            return ServerResponse.createByErrorMessage("请登录！");
        }
        if (!redisApi.exists(token)) {
            return ServerResponse.createByErrorMessage("token失效,请重新登录");
        }

        ItripUser itripUser = JSON.parseObject(redisApi.get(token), ItripUser.class);
        return ServerResponse.createBySuccess(itripUserLinkUserMapper.queryuserLinkUser(itripUser.getId(),linkUserName));

    }

}
